﻿//----------------------------------------------------------------
// Copyright (c) 2011-2013 
// All rights reserved.
// Author: Ben DaoWei 
// Contact: bendaowei@gmail.com
// Web Link: http://xnaeditor.codeplex.com
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using UnityEngine.Graphics;

namespace UnityEngine.Graphics
{
    public class PaletteRendererManager : IDisposable
    {
        private Game _Game;
        private Dictionary<EPaletteRendererType, PaletteRendererContainer> _PaletteRendererContainer;

        ~PaletteRendererManager()
        {
            this.Dispose(false);
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                _PaletteRendererContainer[EPaletteRendererType.Cliff].Dispose();
                _PaletteRendererContainer[EPaletteRendererType.Doodad].Dispose();
                _PaletteRendererContainer[EPaletteRendererType.Unit].Dispose();
                _PaletteRendererContainer[EPaletteRendererType.Custom].Dispose();
                _PaletteRendererContainer[EPaletteRendererType.Sprite].Dispose();
            }
        }

        public PaletteRendererManager(Game game)
        {
            this._Game = game;

            // Create palette renderers
            _PaletteRendererContainer = new Dictionary<EPaletteRendererType, PaletteRendererContainer>();

            _PaletteRendererContainer.Add(EPaletteRendererType.Cliff, new CliffPaletteRendererContainer(game));
            _PaletteRendererContainer.Add(EPaletteRendererType.Doodad, new DoodadPaletteRendererContainer(game));
            _PaletteRendererContainer.Add(EPaletteRendererType.Unit, new UnitPaletteRenderContainer(game));
            _PaletteRendererContainer.Add(EPaletteRendererType.Custom, new CustomPaletteRenderContainer(game));
            _PaletteRendererContainer.Add(EPaletteRendererType.Sprite, new SpritePaletteRendererContainer(game));
        }

        public PaletteRenderer GetPaletteRenderer(EPaletteRendererType PaletteType, string name)
        {
            return _PaletteRendererContainer[PaletteType].GetPaletteRenderer(name);
        }

        public PaletteRendererContainer this[EPaletteRendererType type]
        {
            get { return _PaletteRendererContainer[type]; }
        }
    }
}
